package com.yx.fx.sys.web.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yx.fx.common.model.response.Outcome;
import com.yx.fx.sys.db.entity.SysRole;
import com.yx.fx.sys.web.business.SysRoleBusiness;
import com.yx.fx.sys.web.model.find.FindRolePage;
import com.yx.fx.sys.web.model.save.SaveRole;
import com.yx.fx.sys.web.model.update.ResetUserRole;
import com.yx.fx.sys.web.model.update.UpdateRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import java.util.List;

/**
 * @author 杨智杰
 * @since 2021/8/25 11:02
 */
@Api(tags = "角色相关接口")
@RestController
@RequestMapping("/sys/role")
public class SysRoleApi {

    @Resource
    private SysRoleBusiness sysRoleBusiness;

    @GetMapping
    @ApiOperation("分页")
    public Outcome<IPage<SysRole>> page(FindRolePage param) {
        return Outcome.success(sysRoleBusiness.page(param));
    }

    @PostMapping
    @ApiOperation("新增")
    public Outcome save(@RequestBody @Valid SaveRole param) {
        return sysRoleBusiness.save(param);
    }

    @PutMapping
    @ApiOperation("修改")
    public Outcome update(@RequestBody @Valid UpdateRole param) {
        return sysRoleBusiness.update(param);
    }

    @DeleteMapping
    @ApiOperation("删除")
    public Outcome delete(@RequestBody @Valid @Size(min = 1) List<Long> id) {
        return Outcome.status(sysRoleBusiness.delete(id));
    }

    @PostMapping("/reset")
    @ApiOperation("重置用户角色关联")
    public Outcome reset(@RequestBody @Valid ResetUserRole param) {
        return sysRoleBusiness.reset(param);
    }

}
